Skip to content

Fix examples whose documented output doesn't match Run code - #5718

Merged
kamil-tekiela merged 6 commits into
php:masterfrom
KentarouTakeda:fix-screen-mismatch-mechanical
Jul 31, 2026
Merged

Fix examples whose documented output doesn't match Run code#5718
kamil-tekiela merged 6 commits into
php:masterfrom
KentarouTakeda:fix-screen-mismatch-mechanical

Conversation

@KentarouTakeda

@KentarouTakeda KentarouTakeda commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Every example that has a Run code button and declares its output with &example.outputs; (832 of them) was run and compared against its <screen>.

This PR is the subset where the fix needs no judgement: each hunk can be confirmed by clicking Run code on the page.

One commit per group:

  • Broken examples: two have no <?php so Run code prints the source instead of running it, one calls getName() on the getShortName() page.
  • DOM XML declaration: saveXML() emits it, the screen drops it or drops the encoding the document declares.
  • Formatting var_dump()/print_r() never produce: indentation, [0] => for [0]=>, hand alignment, spaces where the data holds tabs.
  • Wrong values: stale line numbers and offsets, a wrong ordering, a dropped semicolon, output split across lines that is really printed on one.
  • One example read date('T') with no timestamp, so the page was right only half the year; the timestamp is now pinned and the screen is unchanged.
Pages to reproduce this on

Click any page and press Run code: the output that appears is what this PR puts in the <screen>. The static <screen> still shown on these pages is the "before" side of the diff, until the manual is rebuilt.

Fix two broken examples

Fix the XML declaration in DOM blocks

Use the formatting var_dump() and print_r() actually produce

Fix values that do not match the actual output

Pin the timestamp in the date('T') example

Comment thread language/control-structures/goto.xml Outdated
Comment thread language/types/array.xml
Comment thread reference/datetime/functions/date-sun-info.xml
Comment thread reference/dom/dom/htmldocument/createfromstring.xml Outdated
Comment thread reference/libxml/functions/libxml-get-errors.xml
Comment thread reference/pcre/functions/preg-replace.xml Outdated
withfragment.xml had no opening <?php, so pressing Run code printed the
source instead of running it.

getshortname.xml called getName() on the ReflectionConstant::getShortName()
page, so it printed the fully qualified name.
saveXML() emits the declaration, but these screens either drop it
entirely or drop the encoding the document declares.
These screens use indentation, spacing or a layout the functions never
emit: "[0] => " where var_dump() writes "[0]=>" on its own line, hand
alignment print_r() does not pad, and spaces where the data holds tabs.
Each of these differs from what the example prints: stale line numbers
and offsets, a wrong ordering, a dropped semicolon, a missing line,
screens quoting the example's own strings wrongly, and output split
across lines that is really printed on one.
date('T') with no timestamp follows daylight saving, so the page showed
PST for half the year and PDT for the other half. Pinning a winter
moment makes the documented output true all year, so the <screen> is
unchanged.
- goto: drop the stack trace, which PHP 8.5 adds and 8.2-8.4 do not, and
  mark the screen as similar output instead
- object to array cast: split the screen into PHP 8.0 and PHP 8.1, the
  version where the property order changed
- createFromString: indent the source by four spaces rather than remove a
  space from the output
- preg_replace: echo a newline so the count stays on its own line

@kamil-tekiela kamil-tekiela left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jordikroon Is the CI failure something we should be concerned with?

@KentarouTakeda
KentarouTakeda force-pushed the fix-screen-mismatch-mechanical branch from 8feb8e0 to 1d0c3e2 Compare July 31, 2026 17:52
@kamil-tekiela
kamil-tekiela merged commit 17c2385 into php:master Jul 31, 2026
2 checks passed
@KentarouTakeda

Copy link
Copy Markdown
Contributor Author

Mine, and it's fixed — green after a rebase onto master.

Any branch based before #5682 fails the style check. That's most of the open PRs right now, so they'll go red on their next run until rebased.

@KentarouTakeda
KentarouTakeda deleted the fix-screen-mismatch-mechanical branch July 31, 2026 18:02
KentarouTakeda added a commit to php/doc-ja that referenced this pull request Aug 1, 2026
## 概要

php/doc-en@17c2385178 (php/doc-en#5718) への追従。

変更はすべてコード例の実行結果(`<screen>`)と、実行結果と食い違っていた
コード(`<programlisting>`)の修正で、訳文は変更していない。
個々の修正内容とその根拠は php/doc-en#5718 を参照。

## 対象ファイル(45件)

### language(9件)
- types/{array,callable}.xml
- control-structures/{switch,foreach,goto,match}.xml
- oop5/{basic,lazy-objects,overloading}.xml

### reference(36件)
- strings/functions/{explode,rtrim,ltrim,trim,str-word-count,strtok,htmlentities}.xml
- array/functions/{array-map,array-fill,array-udiff-assoc,array-unique,array-unshift,natsort}.xml
- dom/dom/characterdata/{before,remove,replacewith}.xml
- dom/dom/htmldocument/createfromstring.xml
- dom/domdocument/append.xml
- dom/domdocumentfragment/replacechildren.xml
- dom/domelement/{before,getattributenames}.xml
- dom/domnode/getlineno.xml
- datetime/formats.xml
- datetime/functions/{date-default-timezone-get,date-sun-info}.xml
- reflection/reflectionclass/{getdefaultproperties,getdoccomment}.xml
- reflection/reflectionconstant/getshortname.xml
- simplexml/functions/simplexml-load-string.xml
- simplexml/simplexmlelement/{children,getDocNamespaces}.xml
- libxml/functions/{libxml-get-errors,libxml-set-external-entity-loader}.xml
- pcre/functions/preg-replace.xml
- uri/uri/rfc3986/uri/withfragment.xml
- xmlwriter/xmlwriter/writecdata.xml

## その他

- `strings/functions/ltrim.xml` は EN-Revision の範囲に
  php/doc-en@46efd98053 (php/doc-en#5726) の `mb_ltrim` → `ltrim` も入るため併せて追従した。
- `strings/functions/strtok.xml` は追従対象の `<screen>` 内に ja 固有の余分な空行があったので除去した。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants